package cn.edu.thu.laud.lasql.processor;

import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.cql.SelectExpression;
import org.apache.cassandra.cql.SelectStatement;
import org.apache.cassandra.cql.Term;
import org.apache.cassandra.cql.WhereClause;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.InvalidRequestException;

import cn.edu.thu.laud.db.marshal.LaUDFileType;
import cn.edu.thu.laud.se.storage.fs.LaUDFile;
import cn.edu.thu.laud.server.thrift.FileInfo;

public class LaUDSelectStatement extends SelectStatement {

	public LaUDSelectStatement(SelectExpression expression,
			boolean isCountOper, String keyspace, String columnFamily,
			ConsistencyLevel cLevel, WhereClause clause, int numRecords) {
		super(expression, isCountOper, keyspace, columnFamily, cLevel, clause,
				numRecords);
	}
	
	public Map<String,FileInfo> getFileInfos(){	
		if(this.isWildcard()){
			return  null;
		}else{
			Map<String, FileInfo> map=new HashMap<String, FileInfo>();;
			CFMetaData metaData=Schema.instance.getCFMetaData(getKeyspace(),getColumnFamily());
			AbstractType columnNameType=metaData.comparator;	
			List<Term> columns=this.getColumnNames();
			for(Term column:columns){
				try {
					AbstractType type=metaData.getValueValidator(column.getByteBuffer(columnNameType));
					if(type instanceof LaUDFileType){
						//TODO
					}
				} catch (InvalidRequestException e) {
				}
			}
			return map.size()==0?null:map;
		}
	}



}
